package pack08_covid_grouping;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author lilulu
 * @date 2023/2/11 14:23
 */
public class CovidGroupingMapper extends Mapper<LongWritable, Text, CovidGroupingBean, Text> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //1:数据预处理
        String[] split = value.toString().split(",");
        if (split.length < 6) {
            return;
        }
        //2:得到K2
        CovidGroupingBean covidGroupingBean = new CovidGroupingBean();
        covidGroupingBean.setState(split[2]);
        covidGroupingBean.setCases(Integer.parseInt(split[4]));
        context.write(covidGroupingBean,value);
    }
}
